package com.functest.orm

import com.functest.framework.BaseFunctionalTest
import org.testng.annotations.DataProvider
import org.testng.annotations.Test

/**
 * Created with IntelliJ IDEA.
 * User: KovalevAS
 * Date: 26.08.13
 * Time: 18:19
 * To change this template use File | Settings | File Templates.
 */
class MultiMapperTest extends BaseFunctionalTest{
    class Foo{
        int id
        int second

        Foo(int id){
            this.id = id
            this.second = id
        }
    }

    @DataProvider
    Object [][] mapBackData(){
        Mapper firstMapper = new Mapper(
                new MapperFields().with {
                    field('id')
                    delegate as MapperFields
                }
        )
        Mapper secondMapper = new Mapper(
                new MapperFields().with {
                    field('second','id')
                    delegate as MapperFields
                }
        )
        List<Mapper> mappersList = [firstMapper, secondMapper]
        MultiMapper multiMapper = new MultiMapper(mappersList, 'id')

        int value = 193891
        Foo foo = new Foo(value)

        Map columnAliases = [id:'_id']
        Map expectedMap = [id:value, _id:value]

        [[multiMapper, foo, columnAliases, expectedMap]]
    }

    @Test(dataProvider = 'mapBackData')
    void mapBackTest(MultiMapper multiMapper, Foo foo, Map columnAliases, Map expectedResult) {
        Map res = multiMapper.mapBack(foo, columnAliases)
        assert res == expectedResult
    }



}
